import { ref, watch } from 'vue'

export function useDarkTheme() {
  const isDark = ref(localStorage.getItem('isDark') || '0')
  watch(isDark, (val) => {
    if (val == '1') {
      document.documentElement.classList.add('dark')
    } else {
      document.documentElement.classList.remove('dark')
    }
    localStorage.setItem('isDark', val)
  }, { immediate: true })

  return {
    isDark
  }
}

